﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using FOModels.Partner;
namespace DataAccess.Partner
{
    public class PartnerDAL
    {
        SQLDataAccess db;
        public PartnerDAL()
        {
            db = new SQLDataAccess();
        }

        public DataTable getPartnerGroup()
        {
            return db.exeSelect("select * from PartnerGroup");
        }
        public DataTable getPartnerList()
        {
            return db.exeSelect("select top 6 * from Partner ");
        }
        public DataTable getPartnerListJson()
        {
            return db.exeSelect("select * from Partner p join PartnerGroup pg on p.PartnerGroupID = pg.PartnerGroupID ");
        }
        public DataTable getPartnerByGroupID(int groupid)
        {
            return db.exeSelect("select * from Partner where PartnerGroupID = " + groupid + "");
        }
        public DataTable getPartnerByID(int id)
        {
            return db.exeSelect("select * from Partner where PartnerID = " + id + "");
        }
        public DataTable getPartnerGroupByGroupID(int groupid)
        {
            return db.exeSelect("select * from PartnerGroup where PartnerGroupID = " + groupid + "");
        }
        public int UpdatePartnerGroup(PartnerGroup models)
        {
            return db.exeUpdate("update PartnerGroup set PartnerGroupName = N'" + models.PartnerGroupName + "' where PartnerGroupID = " + models.PartnerGroupID + "");
        }
        public int InsertPartnerGroup(PartnerGroup models)
        {
            return db.exeUpdate("insert into PartnerGroup values (N'" + models.PartnerGroupName + "')");
        }
        public int DeletePartnerGroup(int PartnerGroupID)
        {
            return db.exeUpdate("Delete from PartnerGroup where PartnerGroupID = " + PartnerGroupID + "");
        }
        public int UpdatePartner(PartnerModels models)
        {
            return db.exeUpdate("update Partner set PartnerName = N'" + models.PartnerName + "',PartnerImg=N'" + models.PartnerImg + "',PartnerUrl='" + models.PartnerUrl + "',PartnerGroupID=" + models.PartnerGroupID + " where PartnerID = " + models.PartnerID + "");
        }
        public int InsertPartner(PartnerModels models)
        {
            return db.exeUpdate("insert into Partner values (N'" + models.PartnerName + "',N'" + models.PartnerImg + "','" + models.PartnerUrl + "'," + models.PartnerGroupID + ")");
        }
        public int DeletePartner(int PartnerID)
        {
            return db.exeUpdate("Delete from Partner where PartnerID = " + PartnerID + "");
        }

        //EN

        public DataTable getPartnerGroup_EN()
        {
            return db.exeSelect("select * from PartnerGroup_EN");
        }
        public DataTable getPartnerList_EN()
        {
            return db.exeSelect("select top 6 * from Partner_EN ");
        }
        public DataTable getPartnerListJson_EN()
        {
            return db.exeSelect("select * from Partner_EN p join PartnerGroup_EN pg on p.PartnerGroupID = pg.PartnerGroupID ");
        }
        public DataTable getPartnerByGroupID_EN(int groupid)
        {
            return db.exeSelect("select * from Partner_EN where PartnerGroupID = " + groupid + "");
        }
        public DataTable getPartnerByID_EN(int id)
        {
            return db.exeSelect("select * from Partner_EN where PartnerID = " + id + "");
        }
        public DataTable getPartnerGroupByGroupID_EN(int groupid)
        {
            return db.exeSelect("select * from PartnerGroup_EN where PartnerGroupID = " + groupid + "");
        }
        public int UpdatePartnerGroup_EN(PartnerGroup models)
        {
            return db.exeUpdate("update PartnerGroup_EN set PartnerGroupName = N'" + models.PartnerGroupName + "' where PartnerGroupID = " + models.PartnerGroupID + "");
        }
        public int InsertPartnerGroup_EN(PartnerGroup models)
        {
            return db.exeUpdate("insert into PartnerGroup_EN values (N'" + models.PartnerGroupName + "')");
        }
        public int DeletePartnerGroup_EN(int PartnerGroupID)
        {
            return db.exeUpdate("Delete from PartnerGroup_EN where PartnerGroupID = " + PartnerGroupID + "");
        }
        public int UpdatePartner_EN(PartnerModels models)
        {
            return db.exeUpdate("update Partner_EN set PartnerName = N'" + models.PartnerName + "',PartnerImg=N'" + models.PartnerImg + "',PartnerUrl='" + models.PartnerUrl + "',PartnerGroupID=" + models.PartnerGroupID + " where PartnerID = " + models.PartnerID + "");
        }
        public int InsertPartner_EN(PartnerModels models)
        {
            return db.exeUpdate("insert into Partner_EN values (N'" + models.PartnerName + "',N'" + models.PartnerImg + "','" + models.PartnerUrl + "'," + models.PartnerGroupID + ")");
        }
        public int DeletePartner_EN(int PartnerID)
        {
            return db.exeUpdate("Delete from Partner_EN where PartnerID = " + PartnerID + "");
        }

    }
}

